<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6">
            <a-form-item label="题名">
              <a-input placeholder="请输入题名" v-model="queryParam.tiMing"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6">
            <a-form-item label="归档机构">
              <j-select-depart v-model="queryParam.guiDangJiGou"></j-select-depart>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6">
              <a-form-item label="保管期限">
                <j-dict-select-tag
                  type="list"
                  v-model="queryParam.baoGuanQiXian"
                  dictCode="BaoGuanQiXian"
                  placeholder="请选择保管期限"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6">
              <a-form-item label="归档年度">
                <j-dict-select-tag
                  type="list"
                  v-model="queryParam.nianDu"
                  dictCode="NianDu"
                  placeholder="请选择归档年度"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6">
              <a-form-item label="密级">
                <j-dict-select-tag
                  type="list"
                  v-model="queryParam.miJi"
                  dictCode="MiJi"
                  placeholder="请选择密级"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6">
              <a-form-item label="流转状态">
                <j-dict-select-tag
                  type="list"
                  v-model="queryParam.liuZhuanZhuangTai"
                  dictCode="liuZhuanZhuangTai"
                  placeholder="请选择流转状态"
                />
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button @click="juanWenjian" type="primary">卷内文件</a-button>
      <a-button @click="paiXu" type="primary">排序</a-button>
      <a-button @click="guiDang" type="primary">预归档</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('档案管理-文书档案-文书-档案卷')">导出</a-button>
      <!-- <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)"
          >下载</a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a :disabled="record.liuZhuanZhuangTai<5?false:true" @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <!-- <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />-->
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a :disabled="record.liuZhuanZhuangTai<5?false:true">删除</a>
          </a-popconfirm>
          <!-- <a-dropdown>
            <a class="ant-dropdown-link">
              更多
              <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>
        <span slot="detail" slot-scope="text, record" style="color: #1890FF;cursor: pointer;">
          <a @click="handleDetail(record)">{{text}}</a>
        </span>
        <span slot="yeshu" slot-scope="text, record" style="color: #1890FF;cursor: pointer;">
          <router-link
            :to="{name:'juanjian',query:{id:record.id,st:record.liuZhuanZhuangTai<5?false:true}}"
          >{{text}}</router-link>
        </span>
      </a-table>
    </div>

    <daJuan-modal ref="modalForm" @ok="modalFormOk"></daJuan-modal>
  </a-card>
</template>

<script>
import { getAction, postAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import DaJuanModal from './modules/DaJuanModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
export default {
  name: 'DaJuanList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    DaJuanModal,
    JDictSelectTag,
    JSelectDepart,
  },
  data() {
    return {
      description: '档案管理-文书档案-文书-档案卷管理页面',
      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 18 },
        },
      },
      // 表头
      columns: [
        // {
        //   title: '序号',
        //   dataIndex: 'ciXu',
        //   key: 'rowIndex',
        //   width: 80,
        //   align: 'center',
        //   // customRender: function(t, r, index) {
        //   //   return parseInt(index) + 1
        //   // }
        // },
        {
          title: '案卷号',
          width: 100,
          align: 'center',
          dataIndex: 'anJuanHao',
        },
        {
          title: '题名',
          align: 'center',
          dataIndex: 'tiMing',
          scopedSlots: { customRender: 'detail' },
        },
        {
          title: '密级',
          align: 'center',
          dataIndex: 'miJi_dictText',
        },
        {
          title: '归档机构',
          align: 'center',
          dataIndex: 'jiGouMingCheng',
          // customRender: function(t, r, index) {
          //   return parseInt(index) + 1
          // }
        },
        {
          title: '保管期限',
          align: 'center',
          dataIndex: 'baoGuanQiXian_dictText',
        },
        {
          title: '归档年度',
          align: 'center',
          dataIndex: 'nianDu',
        },
        {
          title: '卷内文件',
          align: 'center',
          dataIndex: 'count',
          scopedSlots: { customRender: 'yeshu' },
        },
        {
          title: '流转状态',
          align: 'center',
          dataIndex: 'liuZhuanZhuangTai_dictText',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          // fixed:"right",
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/daJuan/list',
        delete: '/daJuan/delete',
        deleteBatch: '/daJuan/deleteBatch',
        exportXlsUrl: '/daJuan/exportXls',
        importExcelUrl: '/daJuan/importExcel',
      },
      dictOptions: {},
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    // 归档
    guiDang() {
      if (this.selectedRowKeys.length > 0) {
        let ids = this.selectedRowKeys.join()
        postAction('/daJuan/preArchive', { ids }).then((res) => {
          if (res.code == 200) {
            this.$message.success(res.message)
            this.loadData()
          } else {
            this.$message.error(res.message)
          }
        })
      } else {
        this.$message.error('请选择要归档的数据!')
      }
    },
    // 排序
    paiXu() {
      this.$router.push({ path: '/juanpx' })
    },
    // 卷内文件
    juanWenjian() {
      if (this.selectedRowKeys.length == 1) {
        let id = this.selectedRowKeys.join()
        let liuZhuanZhuangTai = []
        let st = false
        this.selectionRows.forEach((i) => {
          liuZhuanZhuangTai = i.liuZhuanZhuangTai
        })
        if (liuZhuanZhuangTai > 4) {
          st = true
        } else {
          st = false
        }
        this.$router.push({ path: '/juanjian', query: { id: id, st: st } })
      } else {
        this.$message.error('请选择一条要查看的数据!')
      }
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>